function sum(arr) {
  //   return arr.reduce((total, cur) => (total += cur), 0);
  //   return arr.flat(Infinity).reduce((total, cur) => (total += cur), 0);
  return arr.reduce((total, cur) => (total += cur["a"]), 0);
}

// const arr = [1, [2, 3]];
const arr = [{ a: 1 }, { a: 2 }, { a: 4 }];
console.log(sum(arr));
